package com.crawler.waf.security.services.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

import com.crawler.waf.security.authens.BaseUserInfo;
import com.crawler.waf.security.authens.UserCenterUserDetails;
import com.crawler.waf.security.authens.UserRole;
import com.crawler.waf.security.services.UserDetailsService;

/**
 * 用户详细信息的处理服务的实现类。
 */
public class UserCenterUserDetailsService implements UserDetailsService {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());


    /**
     * 实现加在用户角色信息
     *
     * @return
     */
    public List<UserRole> getUserRoleList(String userId) {
    	Assert.notNull(userId, "userId");
        List<UserRole> roles = new ArrayList<UserRole>();
        //TODO 获取用户角色列表
        return roles;
    }

    /**
     * 向UC发送获取用户信息的请求
     * @return
     */
    public BaseUserInfo getUserInfo(String userId) {
    	Assert.notNull(userId, "userId");
    	//TODO
    	BaseUserInfo userInfo = new BaseUserInfo();
    	userInfo.setUserId(Long.parseLong(userId));
    	return userInfo;
    }

    @Override
    public UserCenterUserDetails loadUserDetailsByUserId(String userId) {
    	BaseUserInfo user = this.getUserInfo(userId);
        logger.info("user:" + user + ",userId:" + userId);
        List<UserRole> roleDetailsCollection = this.getUserRoleList(userId);
        UserCenterUserDetails details = new UserCenterUserDetails(user, roleDetailsCollection);
        return details;
    }

}
